import { useTagsStore } from '@/stores/tag.js'
/** 
 * 监听当前页面关闭事件，并执行相应的操作，用于处理keepAlive缓存的页面
 * @param {Function} callBack 回调函数
*/
export default function useNowCloseTag(callBack){
  onMounted(()=>{
    const tagStore = useTagsStore();
    const route = useRoute()
    let routeName = route.name
    const nowCloseTag = computed(()=>{
      return tagStore.nowCloseTag
    })
    onActivated(()=>{
      routeName = route.name
    })
    onDeactivated(()=>{
      if(nowCloseTag.value === routeName){
        callBack()
        tagStore.setNowCloseTag('')
      }
    })
  })
}